<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>参数配置</title>
    <link rel="icon" th:href="@{/img/icon.ico}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;padding-right: 10px;line-height: 38px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <form class="layui-form" action="" lay-filter="formDemo">
            <div class="layui-form layuimini-form">
                <input type="hidden" name="id">
                <div class="layui-form-item">
                    <label class="layui-form-label required">默认登录密码</label>
                    <div class="layui-input-block">
                        <input type="text" name="defaultPassword" placeholder="请输入" class="layui-input" lay-verify="required" lay-reqtext="请输入默认登录密码" maxlength="32">
                        <tip>系统用户的默认登录密码，例如：123456</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">登录验证码长度</label>
                    <div class="layui-input-block">
                        <input type="number" name="loginCodeLen" placeholder="请输入" class="layui-input" min="4" max="8">
                        <tip>登录界面验证码的长度，默认为4位</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">登录验证码类型</label>
                    <div class="layui-input-block">
                        <select name="loginCodeType">
                            <option th:each="item : ${login}" th:value="${item.code}" th:text="${item.name}"></option>
                        </select>
                        <tip>登录界面验证码的类型，默认为纯数字</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">短信验证码长度</label>
                    <div class="layui-input-block">
                        <input type="number" name="smsCodeLen" placeholder="请输入" class="layui-input" min="4" max="8">
                        <tip>短信验证码的长度，默认为4位</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">短信验证码类型</label>
                    <div class="layui-input-block">
                        <select name="smsCodeType">
                            <option th:each="item : ${sms}" th:value="${item.code}" th:text="${item.name}"></option>
                        </select>
                        <tip>短信验证码的类型，默认为纯数字</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="saveBtn" shiro:hasPermission="sys:param-conf:edit"> 保存 </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript" th:src="@{/js/jquery-3.2.0.min.js}"></script>
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/js/common-table.js}"></script>

<script type="text/javascript" th:inline="javascript">

    layui.use(['form','notice'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            notice = layui.notice;

        var ctxPath = /*[[@{/}]]*/;
        var baseUrl = ctxPath + 'system/sys-param-conf/';

        form.val("formDemo", [[${data}]]);

        // 监听提交
        form.on('submit(saveBtn)', function (res) {
            var data = res.field;
            if(4 > data.loginCodeLen || data.loginCodeLen > 8){
                notice.warning('登录验证码长度介于4-8之间');
                return false;
            }
            if(4 > data.smsCodeLen || data.smsCodeLen > 8){
                notice.warning('短信验证码长度介于4-8之间');
                return false;
            }
            Asurplus.post({
                url: baseUrl + 'update',
                data: JSON.stringify(data)
            }, () => {
                setTimeout(function () {
                    window.location.reload();
                }, 1500)
            })
            return false;
        });
    });
</script>
</body>
</html>
